<template>
  <div class="toast" v-show="isShow">
    <div>{{msg}}</div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      msg: '',
      isShow: false
    }
  },
  methods: {
    show(message, delay = 2000) {
      this.msg = message
      this.isShow = true
      this.timer = setTimeout(() => {
        this.isShow = false
        this.msg = ''
        clearTimeout(this.timer)
      }, delay)
    }
  }
}
</script>

<style scoped>
.toast {
  position: fixed;
  z-index: 999;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 8px 10px;
  color: #fff;
  background-color: rgba(0, 0, 0, 0.7);
}
</style>
